#pragma once
#include <iostream>
#include <string>

typedef void (*callback_t)();
int num = 1;

class Thread
{
public:
    static void *Mythread(void *args)
    {
        Thread*td=static_cast<Thread*>(args);
        td->Entery();
        return nullptr;
    }

public:
    Thread(callback_t cb)
        : _cb(cb), tid(0), threadname(""), start_timestamp(0), isrunning(false)
    {
    }

    void Run()
    {
        threadname = "Thread-" + std::to_string(num++);
        start_timestamp = time(nullptr);
        isrunning = true;
        pthread_create(&tid, nullptr, Mythread, this);
    }
    
    void Entery()
    {
        _cb();
    }
    
    void Join()
    {
        pthread_join(tid,nullptr);
    }

    uint64_t Start_TimeStamp()
    {
        return start_timestamp;
    }

    bool IsRunning()
    {
        return isrunning;
    }

    ~Thread()
    {
    }

private:
    pthread_t tid;
    std::string threadname;
    uint64_t start_timestamp; // 启动时的时间戳
    bool isrunning;
    callback_t _cb;
};